var token = localStorage.getItem('tok');
//我要还款首页接口
$.ajax({
    type: "GET",
    url: $host + '/api/app/return/returnInfo',
    async: true,
    dataType: 'json',
    data: {
        'token': token
    },
    success: function (result) {
        console.log(result);
        //尚无贷款
        if (result.status == 500001) {
            $('.weidaik').show();
            $('.repayment').hide();
        }else if(result.status == 900000){
            console.log(result);
            //有贷款
            $('.weidaik').hide();
            $('.repayment').show();
            var overdue=result.data.overdue;
            var remainingDay=result.data.overdue;//剩余还款时间
            var timer=result.data.returnTime;//还款时间
            var returnTime=new Date(timer).toLocaleDateString();
            var returnAmount=result.data.shouldAmount//应还总额
            var str_yuan = '<span>元</span>';
            //未逾期
            if(overdue==1){
                    $('.jlhkr').text('距离还款日');
                    $('.hksj').text(remainingDay);
                    $('.dqhkrq').text(returnTime);
                    $('.dqyhk').html(returnAmount+str_yuan);
            }else{
                //逾期
                $('.jlhkr').text('已逾期天数');
                $('.hksj').text(remainingDay);
                $('.dqhkrq').text(returnTime);
                $('.dqyhk').html(returnAmount+str_yuan);
            }
        }else{
            window.location.href = "dengluy.html?token="+token
        }
    },
    error: function () {
        console.log('接口错误')
    }
});

//点击线上还款
$('.btn_xianshang').click(function(){
    window.location.href = "xianshanghk.html?token="+token
})
//点击线下还款
$('.btn_xianxia').click(function(){
    window.location.href = "xianxiahk.html?token="+token
})
